/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q2544.java
 * @Author : WangRuoyu
 * @Date 2023/1/30 9:09
 */

package leetcode;

public class Q2544 {
    public int alternateDigitSum(int n) {
        int res = 0;
        int tmp = n % 10;
        int s = 1;

        while (n != 0) {
            res += (tmp * s);
            s *= (-1);
            n /= 10;
            tmp = (n % 10);
        }

        if (s == 1) {
            return -res;
        } else {
            return res;
        }
    }

    public static void main(String[] args) {
        Q2544 sl = new Q2544();
        int n = 521;
        System.out.println(sl.alternateDigitSum(10));
    }
}